/*
 * Balloon.h
 *
 *  Created on: 2012/07/05
 *      Author: weihe
 */

#ifndef BALLOON_H_
#define BALLOON_H_

#include <stdio.h>
#include "Drawable.h"
#include "glex.h"
#include "utility.h"

namespace object {

class Balloon: public Drawable {
	static int count;
	float speed;
	bool exploded;
	int score;
	friend void initList();
public:
	static const Material colorMaterial[];
	static const Material scoreMaterial[];
	static const Material lineMaterial;
	enum ColorType {
		Yellow = 0, Green, LightBlue, DarkBlue, Red, Pink
	};
	enum ScoreType {
		Copper = 0, Silver, Gold, TreasureSilver, TreasureGold
	};
	static const ColorType ColorTypeList[];
	static const ScoreType ScoreTypeList[];
	ColorType colorType;
	ScoreType scoreType;
	Vector4f position;

	static int getCount()
	{
		return count;
	}

	Balloon(Camera *camera, Vector4f position, ColorType colorType,
			ScoreType scoreType);

	virtual ~Balloon();

	void markExploded()
	{
		exploded = true;
	}

	virtual bool update(float dt)
	{
		if (exploded) {
			return false;
		}
		position += Vector4f::Y_AXIS * speed * dt;
		if (position.y > camera->position.y + 100) {
			count--;
			return false;
		}
		return true;
	}

	virtual void draw();
	static Balloon* genBalloon(Camera *camera)
	{
		double r = nextGaussian() * 150 + 10;
		double th = nextDouble() * M_PI * 2;
		float x = camera->position.x + r * cos(th);
		float z = camera->position.z + r * sin(th);
		float y = camera->position.y - 200 + 150 * nextDouble();
		return new Balloon(camera, Vector4f(x, y, z),
				Balloon::ColorTypeList[rand() % 6],
				Balloon::ScoreTypeList[rand() % 5]);
	}

	int getScore() const
	{
		return score;
	}
};

} /* namespace object */
#endif /* BALLOON_H_ */
